<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:insert="~{include :: header('课程卡主列表')}" />
    <th:block th:insert="~{include :: bootstrap-table-css}" />
</head>
<body class="hold-transition">
<div class="container-fluid mb-2">
    <div class="toolbar" id="toolbar" role="group">
        <form id="formId" class="form-inline">
            <a class="btn btn-success mr-1" onclick="$.operate.add();">
                <i class="fa fa-plus"></i> 添加
            </a>
            <input type="text" class="form-control mr-1" name="searchKey" placeholder="请输入卡名称...">
            <select name="status" class="form-control mr-1" th:with="type=${@dict.getType('qdx_card_status')}">
                <option value="">状态</option>
                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
            </select>
            <button type="button" class="btn btn-primary mr-1" onclick="$.table.search()">
                <i class="fa fa-search"></i>
                搜索
            </button>
            <button type="button" class="btn btn-default" onclick="$.form.reset()">
                <i class="fa fa-refresh"></i>
                重置
            </button>
        </form>
    </div>
    <table id="bootstrap-table" class="table-striped"></table>
</div>
<th:block th:insert="~{include :: footer}" />
<th:block th:insert="~{include :: bootstrap-table-js}" />
<script th:inline="javascript">
    var sta = [[${@dict.getType('qdx_card_status')}]];
    $(function() {
        var options = {
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            url: "/card/course/list.json",
            createUrl: "/card/course/add.html",
            modalName: "课程卡",
            columns: [
                {
                    field: 'id',
                    title: 'id'
                },
                {
                    field: 'name',
                    title: '卡名称'
                },
                {
                    field: 'endDate',
                    align: 'center',
                    title: '有效期'
                },
                {
                    field: 'createUser',
                    title: '操作人'
                },
                {
                    field: 'num',
                    align: 'center',
                    title: '数量'
                },
                {
                    field: 'usedNum',
                    align: 'center',
                    title: '已使用数量'
                },
                {
                    field: 'status',
                    align: 'center',
                    title: '状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(sta, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="cardInfo(\'' + row.id + '\')"><i class="fa fa-search"></i>详情</a> ');
                        if(row.status !=3 ){
                            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="closesAll(\'' + row.id + '\')"><i class="fa fa-remove"></i>作废</a>');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    //课程卡详情
    function cardInfo(id) {
        layer.open({
            type: 2,
            area: ['85%', '95%'],
            fix: false,
            maxmin: true,
            shade: 0.3,
            title: "详情",
            content: "/card/course/info.html?cardId="+id
        });
    }

    //关闭课程卡
    function closesAll(cardId) {
        table.set();
        var str ="此作废,会将该组下的所有的课程卡作废";
        $.modal.confirm(str, function() {
            var data = {"cardId":cardId};
            $.operate.submit("/card/closeAll.json", "post", "json", data);
        });
    }
</script>
</body>
</html>